package dao.impl;

import dao.BaseDao;
import dao.SysUserDao;
import pojo.SysUser;

import java.util.List;

/**
 * @author ： Gao
 * @create ：2022-04-05-16:05
 * @Function Description ：
 *
 *
 *
 *
 */
public class SysUserDaoImpl implements SysUserDao {
    private BaseDao baseDao = new BaseDao();
    @Override
    public int addUser(SysUser user) {
        String sql = "insert into sys_user values(DEFAULT,?,?)";
        int i = baseDao.baseUpdate(sql, user.getUsername(), user.getUserPwd());
        return i;
    }
    @Override
    public SysUser findUser(SysUser user){
        String sql = "select uid,username,user_pwd as userPwd from sys_user where username=? and user_pwd=?";
        List<SysUser> sysuserlist = baseDao.baseQuery(SysUser.class, sql, user.getUsername(), user.getUserPwd());
        if(sysuserlist.size()>0){
            return sysuserlist.get(0);
        }
        return null;
    }
    @Override
    public SysUser findByUsername(String username){
        String sql = "select uid,username,user_pwd as userPwd from sys_user where username=?";
        List<SysUser> sysuserList = baseDao.baseQuery(SysUser.class, sql, username);
        if(sysuserList.size()>0){
            return sysuserList.get(0);
        }
        return null;

    }
}
